package progetto1.csm.main;

import java.util.Random;

import progetto1.csm.core.DataExporter;
import progetto1.csm.core.Scenario;
import progetto1.csm.core.Statistics;
import progetto1.csm.implementation.CSMScenario;
import progetto1.csm.implementation.CSVFileBuilder;
import progetto1.csm.implementation.DataExporterImp;
import progetto1.csm.implementation.SystemFactory;
import sde.actor.distribution.Distribution;
import sde.actor.distribution.ErlangDistribution;
import sde.actor.distribution.ExponentialDistribution;
import sde.actor.distribution.HyperexponentialDistribution;

public class Main {

	public static void main(String[] args) {
		//variabili per le distribuzioni e per l'ambiente
		double lambdaS0 = 0.01, lambdaS1_1 = 1, lambdaS1_2 = 2.3, lambdaS2 = 0.8, lambdaS3 = 0.6;
		int nS3 = 16;
		double alfaS4[] = { 0.95, 0.05 };
		double lambdaS4[] = { 5, 0.5 };
		double tend = 3 * Math.pow(10, 7);
		int k[] = { 2, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };
		Random random = new Random();
		//Random random = new Random(8089L);//usato per il testing
		//file dei due scenari
		String fileScenario1 = "C:\\Users\\Valerio\\Desktop\\scenario1.csv";
		String fileScenario2 = "C:\\Users\\Valerio\\Desktop\\scenario2.csv";
		
		//settaggio dell'ambiente
		SystemFactory.setTimeSimulation(tend);
		// creazione esportatori
		DataExporter de[] = {
				new DataExporterImp(new CSVFileBuilder(fileScenario1)),
				new DataExporterImp(new CSVFileBuilder(fileScenario2)) };
		progetto1.csm.core.System sys;// variabile del sistema
		// simulazioni
		for (int i = 0; i < 2; i++) {
			System.out.println("Simulazione scenario " + (i+1));
			
			for (int j = 0; j < k.length; j++) {
				//distribuzioni
				Distribution d0 = new ExponentialDistribution(lambdaS0, random);
				Distribution d1[] = new Distribution[]{new ExponentialDistribution(lambdaS1_1, random),new ExponentialDistribution(lambdaS1_2, random)};
				Distribution d2 = new ExponentialDistribution(lambdaS2, random);
				Distribution d3 = new ErlangDistribution(nS3, lambdaS3, random);
				Distribution d4 = new HyperexponentialDistribution(alfaS4, lambdaS4, random);
				Scenario s =  new CSMScenario(d0, d1[i], d2, d3, d4);
				sys = SystemFactory.create(s);
				System.out.println("Inizio simuzione scenario " + (i+1) + ", K:"+ k[j]);
				Statistics res = sys.simulate(k[j]);// simulo e stimo le statistiche
				System.out.println("Fine simuzione scenario " + (i+1) + ", K:"+ k[j]);
				de[i].export(res);// esporto le statistiche
			}
			de[i].endExporting();// fine esportazione
			System.out.println("Fine simulazione scenario " + (i+1));
		}
	}
}
